<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<!--{include file='comm/header.tpl'}-->
    <!--{if !$permission_array}-->
    <title>新增权限</title>
    <!--{else}-->
    <title>修改权限</title>
    <!--{/if}-->
</head>
<body>
	
	<div style="width:100%">
		
		<div class="items clearfix">

			<h2 class="tal">
				<!--{if !$permission_array}-->
                    新增权限
			    <!--{else}-->
			    	修改权限
			    <!--{/if}-->
			</h2>
        	<div class="items2">

        		<form id="addForm" onsubmit="return false;">
					<table>
						<tr>
							<td width="150" class="tar">权限号：</td>
							<td width="*" class="td_input" >
								<input type="text" name='permissionID' style="width:100px;ime-mode:active" value="<!--{$permission_array.permissionID}-->" />
								<input type="hidden" name='uuid' value="<!--{$permission_array.uuid}-->" />
							</td>
						</tr>
						<tr>
							<td class="tar">权限名称：</td>
							<td>
								<input type="text" style="width:200px" name="permissionName" value="<!--{$permission_array.permissionName}-->" />
							</td>
						</tr>
						<tr>
							<td class="tar">权限组名：</td>
							<td>
								<select name="permissionGroupID" style="width:218px;">
                                    <option value="0">请选择</option>
                                    <!--{foreach from=$permission_group_array item=groupList}-->
                                        <!--{if $groupList.permissionGroupID == $permission_array.permissionGroupID}-->
                                            <option value='<!--{$groupList.permissionGroupID}-->' selected="selected"><!--{$groupList.permissionGroupName}--></option>
                                        <!--{else}-->
                                            <option value='<!--{$groupList.permissionGroupID}-->'><!--{$groupList.permissionGroupName}--></option>
                                        <!--{/if}-->
                                    <!--{/foreach}-->
                                    <option value="-1">新建权限组</option>
								</select>
                                <span class="hide" id="newGroup"><input type="text" name="newGroup" style="width:176px;" /></span>
							</td>
						</tr>
						<tr>
							<td class="tar">权限路径：</td>
							<td>
								<input type="text" style="width:400px" name="permissionRequest" value="<!--{$permission_array.permissionRequest}-->" />
							</td>
						</tr>
				  </table>
				</form>
				
        	</div>
		</div>
		
		<div class="bottom_fixbox">
	        <div class="rectbox tac">
                <input type="button" class="btn" onclick="permission.save();" value="保存">
				<input type="button" class="btn" onclick="E.closeWindows();" value="关闭">
	        </div>
	    </div>
		
	</div>

<script type="text/javascript">
    var permission = {

        uuid: "<!--{$permission_array.uuid}-->",

        dt: "",

        save: function() {

            var error_msg = "";
            this.dt = E.getFormValues("addForm");

            if (!E.isInt(this.dt.permissionID) || this.dt.permissionID <= 0) {
                error_msg += "请输入权限号<br>";
            }

            if (E.isEmpty(this.dt.permissionName)) {
                error_msg += "请输入权限名称<br>";
            }

            if (this.dt.permissionGroupID == 0) {
                error_msg += "请选择权限组<br>";
            } else if (this.dt.permissionGroupID == -1 && E.isEmpty(this.dt.newGroup)) {
                error_msg += "请输入新权限组名称<br>";
            }

            if (E.isEmpty(this.dt.permissionRequest)) {
                error_msg += "请输入权限路径<br>";
            }

            if (error_msg != "") {
                E.alert(error_msg);
            } else {
                E.loadding.open("正在保存权限，请稍候...");
                E.ajax_post({
                    url: "/invokingAjax-backend/project/permission.ajax?operFlg=2",
                    data: this.dt,
                    call: "permission.result"
                });
            }

        },

        result: function( o ) {

            E.loadding.close();
            if (o.code == 200) {

                if (this.uuid) {
                    E.alert(o.message, 2, "E.closeWindows");
                } else {
                    E.alert(o.message, 2);
                    $("input[name=permissionID]").val("");
                    $("input[name=permissionName]").val("");
                    $("input[name=permissionRequest]").val("");
                }

            } else {

                E.alert(o.message);

            }

        }

    };

    $(window).ready(function() {

        $("select[name=permissionGroupID]").change(function() {
            var id = $(this).val();
            if (id == -1) {
                $("#newGroup").removeClass("hide");
            } else {
                $("#newGroup").addClass("hide").find("input").val("");
            }
        });

    });

</script>
	
</body>
</html>